package com.ks.core.secret.oauth2;

import cn.hutool.crypto.digest.DigestUtil;
import com.ks.core.util.GenerateNumberUtil;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @author kingdee
 */
public class Oauth2Util {
    private Oauth2Util() {
    }

    private static final String SERVER_NAME = "DFYH_SERVER";

    /**
     * 生成appKey
     *
     * @return appKey
     */
    public static String appKey() {
        return GenerateNumberUtil.getGuid2();
    }

    /**
     * 通过appId和内置关键词生成APP Secret
     *
     * @param appKey appKey
     * @return APP Secret
     */
    public static String appSecret(String appKey) {
        return DigestUtil.sha1Hex(Arrays.stream(new String[]{appKey, SERVER_NAME}).sorted().collect(Collectors.joining()));
    }
}
